#read `Jet.m`: 
coordinates([t,x],[u]): ;

Quiet := true:
#Quiet := false:

printlevel := 4:
OK := true:
T := proc (a,b,c)
  global OK;
  if not Quiet then lprint(c) fi;
  if not a=b then
    lprint (`Incorrect result`, a);
    lprint (`instead of`, b);
    lprint (`while testing`, c);
    lprint ();
    OK := false
  fi
end:
Ts := proc ()
  local a,b,c; global OK;
  a := args[1]; b := {args[2..nargs-1]}; c := args[nargs];
  if not Quiet then lprint(c) fi;
  if not member(a,b) then
    lprint (`Incorrect result`, a);
    lprint (`neither of`, op(b));
    lprint (`while testing`, c);
    lprint ();
    OK := false
  fi
end:

time0 := time():

##Quiet := false;

T (sizesort([[2,1], [3,2,1], []], nops), [[], [2,1], [3,2,1]], `sizesort 1`):

T (reduceprod(3*a^m*b^2*c/d), 3*a^m*b*c, `reduceprod 1`):
T (reduceprod((a + b)^2), a + b, `reduceprod 2`):

equations ():
x := 'x': t := 't': u := 'u':
coordinates([t,x],[u]): 
T (`b/var/s`, {x,t}, `base 1`):
T (`b/dim`, 2, `base 2`):
T (`f/var/s`, {u}, `fibre 1`):
T (`f/dim`, 1, `fibre 2`):
T (type (x, `b/var`), true, `b/var`):
T (type (u, `f/var`), true, `f/var`):
T (type ('jet(u,x^2*t^3)', `j/var`), true, `j/var`):

p := 'p': q := 'q':
T (type (p*q^2, 'count'), true, `count 1`):
T (type (p/q^2, 'count'), false, `count 2`):
T (type (1, 'count'), false, `count 3`):
T (type (x^2*t^3, `b/count`), true, `b/count 1`):
T (type (u, `b/count`), false, `b/count 2`):

Ts (`count/f` (x^2*t^3), x, t, `count/f`):
Ts (`count/r` (x^2*t^3), x*t^3, x^2*t^2, `count/r`):

f := 'f': g := 'g': h := 'h':
`dep/tab` := table([]):
dependence (h(x)):
T ({op(op(op(`dep/tab`)))}, {h={x}}, `dependence 1`):
clear(dependence):
T ({op(op(op(`dep/tab`)))}, {}, `clear 1`):

dependence (f(x,u,jet(u,t))):
T ({op(op(op(`dep/tab`)))}, {f={x,u,jet(u,t)}}, `dependence 2`):
clear(dependence):

a := 'a':
clear(parameter):
parameter(a):
dependence (h(a)):
T ({op(op(op(`dep/tab`)))}, {h={a}}, `dependence 3`):
clear(parameter,dependence):

`EVALTD/s` := {}: `EVALTD/b` := false:
T (TD(f), f, `TD 0`):
T (TD(x,x), 1, `TD 1a`): 
T (TD(t,x), 0, `TD 1b`): 
T (TD(u,x), 'jet(u,x)', `TD 2a`): 
T (TD(jet(u,x),t), 'jet'(u,x*t), `TD 2b`): 
dependence (f(x,u),h(x),k(u,jet(u,x))):
T (TD(f,x), 'TD(f,x)', `TD 3a`):
T (TD(g,x), 'TD(g,x)', `TD 3b`):
T (TD(sin(f),x), 'cos(f)'*'TD(f,x)', `TD 4`):
T (TD(f+g,x), 'TD(f,x)'+'TD(g,x)', `TD 5`):
T (TD(f*g,x), 'TD(f,x)'*g+f*'TD(g,x)', `TD 6`):
T (TD(f,x^2*t), 'TD'(f,x^2*t), `TD 7a`):
T (TD(g,x^2*t), 'TD'(g,x^2*t), `TD 7b`):
T (TD(f+g,x^2*t), 'TD'(f,x^2*t) + 'TD'(g,x^2*t), `TD 8`):
T (TD(f*g,x^2), 'TD'(f,x^2)*g + 2*'TD'(f,x)*'TD'(g,x) + f*'TD'(g,x^2), `TD 9`):
clear(dependence):
dependence (h(x)):
T (TD(h,x), pd(h,x), `TD 10a`):
T (TD(h,x^2), pd(h,x^2), `TD 10b`):
T (TD(h,t), 0, `TD 10c`):
T (TD(pd(h,x),x), pd(h,x^2), `TD 11a`):
clear(dependence):
dependence (f(u)):
T (TD(f,t,x), TD(f,t*x), `TD 12a`):
T (TD(TD(f,t),x), TD(f,t*x), `TD 12b`):
clear(dependence):
parameter(a):
T (TD(a,t), 0, `TD 13`):
dependence(h(a,x)):
T (TD(h,x), pd(h,x), `TD 10d`):
T (TD(h,x^2), pd(h,x^2), `TD 10e`):
T (TD(h,t), 0, `TD 10f`):
T (TD(pd(h,x),x), pd(h,x^2), `TD 11b`):
clear(parameter,dependence):

dependence (f(u)):
T (evalTD(TD(f,x)), pd(f,u)*jet(u,x), `evalTD 1`):
T (evalTD(TD(f,x) + TD(g,x), {f}), pd(f,u)*jet(u,x) + TD(g,x), `evalTD 2`):
clear(dependence):

T (TD[x](g), TD(g,x), `TD[] 1`):
T (TD[t*x^2](g), TD(g,t*x^2), `TD[] 2`):

parameter(a):
T (pd(f), f, `pd 0`):
T (pd(f,jet(u,x)), 'pd(f,jet(u,x))', `pd 1a`): 
T (pd(f,a), 'pd(f,a)', `pd 1b`): 
T (pd(u,u), 1, `pd 2a`): 
T (pd(u,jet(u,x)), 0, `pd 2b`): 
T (pd(jet(u,x),u), 0, `pd 2c`): 
T (pd(a,a), 1, `pd 2d`):
T (pd(a,x), 0, `pd 2e`):
T (pd(f,x,u), pd(f,x,u), `pd 2f`):
T (pd(f,a,u), pd(f,a,u), `pd 2g`):
dependence (f(x,u,jet(u,x))):
T (pd(f,jet(u,t)), 0, `pd 3a`): 
T (pd(f,a), 0, `pd 3b`): 
T (pd(sin(f),u), 'cos(f)'*'pd(f,u)', `pd 4`):
T (pd(f+g,u), 'pd(f,u)'+'pd(g,u)', `pd 5`):
T (pd(f*g,u), 'pd(f,u)'*g+f*'pd(g,u)', `pd 6`):
T (pd(f+g,u^2*jet(u,x)), 'pd(f,u^2*jet(u,x))'+'pd(g,u^2*jet(u,x))',
 `pd 7`):
T (pd(f*g,u^2), 'pd(f,u^2)'*g + 2*'pd(f,u)'*'pd(g,u)' + f*'pd(g,u^2)',
 `pd 8`):
T (pd(f,a), 0, `pd 9a`):
dependence (f(a,x,u)):
T (pd(f,a), 'pd(f,a)', `pd 9b`):
T (pd(f,a,u), 'pd(f,a*u)', `pd 9c`):
clear(parameter):

parameter(a):
dependence (f(a,x,u)):
T (pd(TD(f,x), jet(u,x)), 'pd(f,u)', `pdTD 1`):
T (pd(TD(f,t*x), jet(u,x)), 'TD(pd(f,u),t)', `pdTD 2`):
T (pd(TD(f,x), a), 'TD(pd(f,a),x)', `pdTD 3`):
clear(parameter,dependence):

dependence (f(x,u)):
T (vars(u), {u}, `vars 1`):
T (vars(f), {x,u}, `vars 2`):
T (vars(jet(u,x)), {jet(u,x)}, `vars 3`):
T (vars(sin(u)), {u}, `vars 4a`):
T (vars(sin(f)), {x,u}, `vars 4b`):
T (vars(pd(f,x)), {x,u}, `vars 5`):
T (vars(TD(f,x)), {x,u,jet(u,x)}, `vars/TD 1`):
T (vars(TD(f,x^3)), {x,u,jet(u,x),jet(u,x^2),jet(u,x^3)}, `vars/TD 2`):
clear(dependence):

equations ('jet(u,t)' = jet(u,x^3) + 6*u*jet(u,x)):
T (`eqn/list`, [(u,t) = jet(u,x^3) + 6*u*jet(u,x)], `equations 0`):
T (jet(u,x*t), 'jet(u,x^4) + 6*jet(u,x)^2 + 6*u*jet(u,x^2)', `equations 1`): 
T (jet(u,t^2), 'jet(u,x^6) + 12*u*jet(u,x^4) + 30*jet(u,x)*jet(u,x^3)
 + 18*jet(u,x^2)^2 + 36*u^2*jet(u,x^2) + 72*u*jet(u,x)^2', `equations 2`):
clear(dependence):

dependence (f(u)):
T (vars(TD(f,x)), {u,jet(u,x)}, `vars/TD 3`):
T (vars(TD(f,t)), {u,jet(u,x),jet(u,x^3)}, `vars/TD 4`):
T (vars(TD(f,t*x)), {u,jet(u,x),jet(u,x^2),jet(u,x^3),jet(u,x^4)}, `vars/TD 5`):

T (evalTD (TD(f,x)), 'pd(f,u)*jet(u,x)', `evalTD 3`):
T (evalTD (TD(f,t)), 'pd(f,u)*(jet(u,x^3) + 6*u*jet(u,x))', `evalTD 4`):

T (pd(TD(f,t), jet(u,x)), 6*u*pd(f,u), `pd/TD 3`):
T (pd(TD(f,t), jet(u,x^3)), 'pd(f,u)', `pd/TD 4`):
T (pd(TD(f,x*t), jet(u,x^3)), 'TD(pd(f,u),x)', `pd/TD 5`):
T (pd(TD(f,x*t), jet(u,x^2)), '6*u*pd(f,u)', `pd/TD 6`):
T (pd(TD(f,t^2), jet(u,x^4)), '12*u*pd(f,u)', `pd/TD 7`):

U := 'U': 
T ([symmetries(u = U)], [TD(U,t) - TD(U,x^3) - 6*TD(U,x)*u - 6*jet(u,x)*U], 
  `symmetries 1`):
F := 'F':
T ([laws(1 = F)], [-TD(F,t) + TD(F,x^3) + 6*u*TD(F,x)], `laws 1`):
equations ():
coordinates([t,x],[u,v]): 
equations ('jet(u,t)' = jet(v,x^2) + u^2, 'jet(v,t)' = -jet(u,x^2) + v^2):
V := 'V':
T ([symmetries(u = U, v = V)],
  [TD(U,t) - TD(V,x^2) - 2*u*U, TD(V,t) + TD(U,x^2) - 2*v*V], `symmetries 2`):
G := 'G':
T ([laws(1 = F, 2 = G)], 
  [-TD(F,t) + TD(G,x^2) - 2*u*F, -TD(G,t) - TD(F,x^2) - 2*v*G], `laws 2`):
equations():
equations ('jet(u,t*x)' = jet(v,t)*jet(v,x), 'jet(v,t*x)' = -jet(u,t)*jet(u,x)):
T ([symmetries(u = U, v = V)], 
  [TD(U,t*x) - jet(v,x)*TD(V,t) - jet(v,t)*TD(V,x), 
  TD(V,t*x) + jet(u,t)*TD(U,x) + jet(u,x)*TD(U,t)], `symmetries 3`):
T ([laws(1 = F, 2 = G)], 
  [TD(F,t*x) - jet(u,t)*TD(G,x) - jet(u,x)*TD(G,t) - 2*jet(v,t)*jet(v,x)*G,
   TD(G,t*x) + jet(v,x)*TD(F,t) + jet(v,t)*TD(F,x) - 2*jet(u,t)*jet(u,x)*F],
  `laws 3`):
equations():

T (unks(F*pd(G,u)), {F,G}, `unks 1`):
clear(dependence):

dependence(F(),G(jet(u,x))):
equations('jet(u,t*x^2)' = F):
T (unks(TD(G,x)), {G}, `unks/TD 1`):
T (unks(TD(G,t)), {G}, `unks/TD 2`):
T (unks(TD(G,t*x)), {F,G}, `unks/TD 3`):
clear(dependence):

put('pd(f,x)' = x^3): 
T (pd(f,x), x^3, `put 1a`):
T (pd(f,x^2), 3*x^2, `put 1b`):
T (pd(f,x^4), 6, `put 1c`):
put('pd(f,u)' = f^2):
T (pd(f,u), f^2, `put 2a`):
T (pd(f,u^2), 2*f^3, `put 2b`):
clear(dependence,pds):

dependence(f(x,u)):
put('pd(f,x)' = 0):
T ([`pd/tab`[f][x],`dep/tab`[f]], [`pd/tab`[f][x],{u}], `put 2c`):
clear(dependence,pds):

h := 'h':
dependence(f(x,u)):
put(h = pd(f,x^2)):
T (h, 'pd(f,x^2)', `put 3`):

f := 'f':
put('pd(f,x)' = pd(f,u), 'pd(f,u)' = f): 
T ({reduce()}, {'pd(f,x) = f', 'pd(f,u) = f'}, `reduce 1`):
clear(dependence,pds):

put('pd(f,x^2)' = 0):
dependence(f(u)): 
T ({reduce()}, {}, `reduce 2`):
clear(dependence,pds):

put('pd(f,x^2)' = u, 'pd(f,x*u)' = x, 'pd(f,x^2*u)' = 1):
T ({reduce()}, {'pd(f,x^2) = u', 'pd(f,x*u) = x'}, `reduce 3`):
clear(dependence,pds,cc):

put('pd(f,x^2)' = u, 'pd(f,x*u)' = x, 'pd(f,x^2*u)' = 1):
T (cc(), {}, `cc 1`):
clear(dependence,pds,cc):

f := 'f': g := 'g': h := 'h':
unknowns(f,g,h):
put('pd(f,x^2)' = g, 'pd(f,x*u)' = h):
Ts (cc(), {pd(g,u) - pd(h,x)}, {pd(h,x) - pd(g,u)}, `cc 2`):
clear(dependence,pds,cc):

put('pd(f,x)' = f):
f := u:
T (cc(), {-u}, `cc 3`):
clear(dependence,pds,cc):

f := 'f':
put('pd(f,x^2)' = x):
dependence(f(u)): 
T (cc(), {x}, `cc 4`):
clear(dependence,pds,cc):

put('pd(f,x^2)' = u^2):
dependence(f(x)): 
T (cc(), {2*u}, `cc 5`):
clear(dependence,pds,cc):

f := 'f':
dependence(f(x)): 
f := x*u^2:
T (cc(), {2*x*u}, `cc 6`):
clear(dependence,pds,cc):

f := 'f':
equations ():
clear(dependence,pds):

T ({divideout(a,{})}, {a}, `divideout 1`):
T ({divideout(a,{a})}, {1}, `divideout 1a`):
T ({divideout(a*b*c,{a,b})}, {c}, `divideout 1b`):
T ({divideout(x*u*a*b,{a,b})}, {1}, `divideout 1c`):
T ({divideout(x*u*a*b,{a,b})}, {1}, `divideout 1d`):

T ({divideout((1+a)*(1+b),{1+a})}, {1+b}, `divideout 2`):
T ({divideout((1+a)/(1+b),{1+a})}, {1/(1+b)}, `divideout 2a`):
T ({divideout((1+a)^3,{1+a})}, {1}, `divideout 2b`):
T ({divideout((1+a)^3*(1+b)^2,{1+a})}, {1+b}, `divideout 2c`):
T ({divideout((1+a)^r*(1+b)^2,{1+a,1+b})}, {(1+a)^r}, `divideout 2d`):

T ({divideout(a*b + a/b,{a})}, {(b^2 + 1)/b}, `divideout 3`):
clear(nonzero):

T (nonzero(a*b), {a,b}, `nonzero 1`):
clear(nonzero):

T (nonzero(a*e,a*f), {a,e,f}, `nonzero 2`):
clear(nonzero):

T (nonzero(1 + a + b + a*b, 1 + a, 1 + b), {1 + a, 1 + b}, `nonzero 3`):
clear(nonzero):

T (type({1 + a},nonzero), false, `type/nonzero 1`):
clear(nonzero):

T (`resolve/lin`({a + b}, [a,b]), a = -b, `resolve 1`):
T ({`resolve/lin`({a + b, a + c}, [a,b,c])}, {a = -c, b = c},`resolve 2`): 
T (`resolve/lin`({c*a + b + 2, b + 5}, [a,b]), b = -5, `resolve 3`):


# sort vars

equations ():
coordinates([t,x],[u,v]): 
fvarord(u,v):
bvarord(t,x):
L := [jet(v,x^2), jet(v,t*x), jet(v,t^2), 
      jet(u,x^2), jet(u,t*x), jet(u,t^2), 
      jet(v,x), jet(v,t), jet(u,x), jet(u,t), v, u, x, t]:
      
`var/<</opt` := ['degree','function','count']:
T (sort(L, `vars/<<`), [t, x, 
  u, v, jet(u,t), jet(u,x), jet(v,t), jet(v,x), 
  jet(u,t^2), jet(u,t*x), jet(u,x^2), 
  jet(v,t^2), jet(v,t*x), jet(v,x^2)],
  `vars/<< dfc`);
  
`var/<</opt` := ['degree','count','function']:
T (sort(L, `vars/<<`), [t, x, 
  u, v, jet(u,t), jet(v,t), jet(u,x), jet(v,x), 
  jet(u,t^2), jet(v,t^2), jet(u,t*x), jet(v,t*x), 
  jet(u,x^2), jet(v,x^2)],
  `vars/<< dcf`);

`var/<</opt` := ['function','degree','count']:
T (sort(L, `vars/<<`), [t, x, 
  u, jet(u,t), jet(u,x), jet(u,t^2), jet(u,t*x), jet(u,x^2), 
  v, jet(v,t), jet(v,x), jet(v,t^2), jet(v,t*x), jet(v,x^2)],
  `vars/<< fdc`);

`var/<</opt` := ['function','count']:
T (sort(L, `vars/<<`), [t, x,
  u, jet(u,t), jet(u,t^2), jet(u,x), jet(u,t*x), jet(u,x^2), 
  v, jet(v,t), jet(v,t^2), jet(v,x), jet(v,t*x), jet(v,x^2)],
  `vars/<< fc`);

`var/<</opt` := ['count','function']:
T (sort(L, `vars/<<`), [t, x,
  u, v, jet(u,t), jet(v,t), jet(u,t^2), jet(v,t^2), 
  jet(u,x), jet(v,x), jet(u,t*x), jet(v,t*x), 
  jet(u,x^2), jet(v,x^2)],
  `vars/<< cf`);



# sort Vars

equations ():
coordinates([t,x],[u,v],2): 
fvarord(u,v):
bvarord(t,x):
unknowns(U,V):
`var/<</opt` := ['degree','function','count']:
L := [pd(V,jet(v,t)^2), pd(V, v*jet(v,t)), pd(V,v^2), 
      pd(U,jet(v,t)^2), pd(U, v*jet(v,t)), pd(U,v^2), 
      pd(V,jet(v,t)), pd(V,v), pd(U,jet(v,t)), pd(U,v), V, U]:



`Var/<</opt` := ['degree','function','count']:
T (sort(L, `Vars/<<`), [U, V, 
  pd(U,v), pd(U,jet(v,t)), pd(V,v), pd(V,jet(v,t)), 
  pd(U,v^2), pd(U, v*jet(v,t)), pd(U,jet(v,t)^2), 
  pd(V,v^2), pd(V, v*jet(v,t)), pd(V,jet(v,t)^2)],
  `Vars/<< dfc`);

`Var/<</opt` := ['degree','count','function']:
T (sort(L, `Vars/<<`), [U, V, 
  pd(U,v), pd(V,v), pd(U,jet(v,t)), pd(V,jet(v,t)), 
  pd(U,v^2), pd(V,v^2), pd(U, v*jet(v,t)), pd(V, v*jet(v,t)), 
  pd(U,jet(v,t)^2), pd(V,jet(v,t)^2)],
  `Vars/<< dcf`);

`Var/<</opt` := ['function','degree','count']:
T (sort(L, `Vars/<<`), [U, pd(U,v), pd(U,jet(v,t)), 
  pd(U,v^2), pd(U, v*jet(v,t)), pd(U,jet(v,t)^2), 
  V, pd(V,v), pd(V,jet(v,t)), 
  pd(V,v^2), pd(V, v*jet(v,t)), pd(V,jet(v,t)^2)],
  `Vars/<< fdc`);

`Var/<</opt` := ['function','count']:
T (sort(L, `Vars/<<`), [U, pd(U,v),  pd(U,v^2), 
  pd(U,jet(v,t)), pd(U, v*jet(v,t)), pd(U,jet(v,t)^2), 
  V, pd(V,v),  pd(V,v^2), 
  pd(V,jet(v,t)), pd(V, v*jet(v,t)), pd(V,jet(v,t)^2)],
  `Vars/<< fc`);

`Var/<</opt` := ['count','function']:
T (sort(L, `Vars/<<`), [U,  V, 
  pd(U,v),  pd(V,v), pd(U,v^2), pd(V,v^2), 
  pd(U,jet(v,t)),  pd(V,jet(v,t)), 
  pd(U, v*jet(v,t)), pd(V, v*jet(v,t)), 
  pd(U,jet(v,t)^2), pd(V,jet(v,t)^2)],
  `Vars/<< cf`);


f := 'f':
dependence (f(x,u,jet(u,x*t))):
T (convert(jet(u,x) + pd(f,jet(u,x*t)^2*u*x^2), TD, u=h^2),
  '2*h*TD(h,x) + pd(f,jet(u,x*t)^2*u*x^2)', `convert/TD`):
equations():
clear(dependence):


A := 'A': B := 'B': C := 'C':
parameter(w):
T ({vectorfield(A,B,C)}, {A,B,C}, `vectorfield 0`); 
T (type (0, vectorfield), true, `vectorfield 1`); 
T (type (A, vectorfield), true, `vectorfield 2`); 
T (type (pd(A,x), vectorfield), true, `vectorfield 3`); 
T (type (TD(A,x), vectorfield), true, `vectorfield 4`); 
T (type (-A, vectorfield), true, `vectorfield 5`); 
T (type (2*A, vectorfield), true, `vectorfield 6a`); 
T (type (A*B, vectorfield), false, `vectorfield 6b`); 
T (type (A*x*w, vectorfield), true, `vectorfield 6c`); 
T (type (A^2, vectorfield), false, `vectorfield 6d`); 
T (type (A + B, vectorfield), true, `vectorfield 7a`); 
T (type (A + 1, vectorfield), false, `vectorfield 7b`); 
T (type (pd[x], vectorfield), true, `vectorfield 8a`); 
T (type (pd[w], vectorfield), true, `vectorfield 8b`); 
T (type (pd[x^2], vectorfield), false, `vectorfield 8b`); 
T (type (TD[x], vectorfield), true, `vectorfield 9a`); 
T (type (TD[x^2], vectorfield), false, `vectorfield 9b`); 
T (type (comm(A,B), vectorfield), true, `vectorfield 10`); 

parameter(w): nonlocal(w):
T (type (w, nonlocal), true, `nonlocal 1`);

T ({tail(E,F)}, {E,F}, `tail 0`);
T (type (0, tail), true, `tail 1`); 
T (type (A, tail), false, `tail 2a`); 
T (type (E, tail), true, `tail 2b`); 
T (type (pd(E,x), tail), true, `tail 3a`); 
T (type (pd(A,x), tail), false, `tail 3b`); 
T (type (TD(E,x), tail), true, `tail 4a`); 
T (type (TD(A,x), tail), false, `tail 4b`); 
T (type (-E, tail), true, `tail 5`); 
T (type (2*E, tail), true, `tail 6a`); 
T (type (A*E, tail), false, `tail 6b`); 
T (type (E*x*w, tail), true, `tail 6c`); 
T (type (E^2, tail), false, `tail 6c`); 
T (type (E + F, tail), true, `tail 7a`); 
T (type (A + F, tail), false, `tail 7a`); 
T (type (E + 1, tail), false, `tail 7b`); 
T (type (pd[x], tail), false, `tail 8a`); 
T (type (pd[w], tail), true, `tail 8b`); 
T (type (pd[w^2], tail), false, `tail 8c`); 
T (type (TD[x], tail), false, `tail 9a`); 
T (type (TD[x^2], tail), false, `tail 9b`); 
T (type (comm(E,F), tail), true, `tail 10a`); 
T (type (comm(A,F), tail), false, `tail 10b`); 
clear(parameter,nonlocal):

parameter(w): nonlocal(w):
T (apply(0,f), 0, `apply 1`); 
T (apply(A + B, f), 'apply(A,f)' + 'apply(B,f)', `apply 2`); 
T (apply(2*A, f), 2*'apply(A, f)', `apply 3a`);
T (apply(x*A, f), x*'apply(A, f)', `apply 3b`);
T (apply(x*w*A, f), x*w*'apply(A, f)', `apply 3c`);
T (apply(pd[x],f), pd(f,x), `apply 4a`); 
T (apply(pd[x],pd[u]), 0, `apply 4b`); 
T (apply(pd[w],TD[x]), 0, `apply 4c`); 
T (apply(pd[u],TD[x]), 'apply'(pd[u],TD[x]), `apply 4d`); 
T (apply(TD[x],f), TD(f,x), `apply 5`); 
T (apply(comm(A,B), f), apply(A,apply(B,f))
     - apply(B,apply(A,f)), `apply 6`); 
T (apply(pd[u],2*TD[x]), 2*'apply'(pd[u],TD[x]), `apply 4e`); 
T (apply(pd[u],2*pd[x]), 0, `apply 4f`); 


T (comm(A,A), 0, `comm 1a`); 
T (comm(A,0), 0, `comm 1b`); 
T (comm(0,B), 0, `comm 1c`); 
T (comm(A + B, C), comm(A, C) + comm(B, C), `comm 2a`);
T (comm(A, B + C), comm(A, B) + comm(A, C), `comm 2b`);
T (comm(2*A, B), 2*comm(A, B), `comm 3a`);
T (comm(A, 2*B), 2*comm(A, B), `comm 3b`);
T (comm(x*A, B), x*comm(A, B) - 'apply'(B,x)*A, `comm 4a`);
T (comm(A, x*B), x*comm(A, B) + 'apply'(A,x)*B, `comm 4b`);
T (comm(2*x*A, B), 2*x*comm(A, B) - 2*'apply'(B,x)*A, `comm 4c`);
T (comm(A, 2*x*B), 2*x*comm(A, B) + 2*'apply'(A,x)*B, `comm 4d`);
T (comm(TD[x], TD[t]), 0, `comm 5a`);
Ts (comm(TD[x], A), 'comm'(TD[x], A), -'comm'(A,TD[x]), `comm 5b`);
T (comm(pd[x], A), apply(pd[x],A), `comm 6a`);
T (comm(A, pd[x]), -apply(pd[x],A), `comm 6b`);
Ts (comm(A,B), 'comm'(A,B), -'comm'(B,A), `comm 7`); 
Ts (comm(A,comm(B,C)), 'comm(A,comm(B,C))', '-comm(A,comm(C,B))',
   'comm(B,comm(A,C)) - comm(C,comm(A,B))',
   `comm 8a`);
Ts (comm(comm(A,B),C), 'comm(C,comm(B,A))', '-comm(C,comm(A,B))', 
   'comm(B,comm(C,A)) - comm(A,comm(C,B))',
   `comm 8b`);
T (comm(A, comm(B,C)) + comm(B, comm(C,A))  + comm(C, comm(A,B)),
   0, `comm 9c`);
T (comm(comm(A,B), C) + comm(comm(B,C), A)  + comm(comm(C,A), B),
   0, `comm 9d`);



if OK then lprint(`O.K.`);
  print(cat(floor(time() - time0),` sec.`))
fi:

